package cn.huanba.service.impl;

import cn.huanba.dao.UserDao;
import cn.huanba.entity.User;
import cn.huanba.service.UserService;
import cn.huanba.utils.RedisUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表服务实现类
 *
 * @author makejava
 * @since 2021-01-07 17:23:28
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;
    @Autowired
    private RedisUtils redisUtils;

    @Override
    public User loginByLoginname(String loginname, String password) {
        return userDao.loginByLoginname(loginname,password);
    }

    @Override
    public User loginByPhone(String phone) {
        return userDao.loginByPhone(phone);
    }

    @Override
    public User getUserByToken(String token) {
        User account=null;
        String value=redisUtils.get(token);
        if(value!=null){
            account= JSONObject.parseObject(value,User.class);
        }
        return account;
    }


}